package com.lctandil.geophotos.clustering;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;

public class Cluster{
	
	private GeoPoint center;
	
	private ArrayList<ImageInfo> infoImages;
	
	public Cluster() {
		this.infoImages = new ArrayList<ImageInfo>();
		this.center = new GeoPoint(0, 0);
	}

	public final GeoPoint getCenter() {
		return center;
	}

	public final void setCenter(GeoPoint center) {
		this.center = center;
	}

	public final ArrayList<ImageInfo> getInfoImages() {
		return infoImages;
	}

	public final void setInfoImages(ArrayList<ImageInfo> infoImages) {
		this.infoImages = infoImages;
	}
	
	public final ImageInfo getFirst(){
		if (this.infoImages.size()>0)
			return this.infoImages.get(0);
		return null;
	}
	
	public final int getCount() {
		return this.infoImages.size();
	}
	
	public final void addImage(final ImageInfo imageInfo) {
		this.infoImages.add(imageInfo);
		calculateCenter();
	}
	
	public final ImageInfo getInfoImage(final int pos){
		return this.infoImages.get(pos);
	}
	
	private void calculateCenter(){
		long latitude = 0;
		long longitud = 0;
		for (int i = 0; i < this.infoImages.size(); i++) {
			ImageInfo info = this.infoImages.get(i);
			latitude +=info.getPoint().getLatitudeE6();
			longitud +=info.getPoint().getLongitudeE6();
		}
		int count= this.infoImages.size();
		this.center=new GeoPoint((int)(latitude/count), (int)(longitud/count));
	}
	

}
